/*
 * @Author: sjr
 * @Date: 2021-02-02 07:23:46
 * @LastEditTime: 2021-02-02 07:35:57
 * @LastEditors: sjr
 * @Description: 描述
 * @FilePath: \leetcode\155.最小栈.js
 */
/*
 * @lc app=leetcode.cn id=155 lang=javascript
 *
 * [155] 最小栈
 */

// @lc code=start
/**
 * initialize your data structure here.
 */
var MinStack = function() {
  this.stack = []
};

/** 
 * @param {number} x
 * @return {void}
 */
MinStack.prototype.push = function(x) {
  this.stack[this.stack.length] = x
};

/**
 * @return {void}
 */
MinStack.prototype.pop = function() {
  this.stack.length--
};

/**
 * @return {number}
 */
MinStack.prototype.top = function() {
 return this.stack[this.stack.length-1]
};

/**
 * @return {number}
 */
MinStack.prototype.getMin = function() {
  let min = this.stack[0]
  let len = this.stack.length
  for(let i = 0;i<len; i++ ){
    if(min > this.stack[i]) {
      min = this.stack[i]
    }
  }
  return min
};

/**
 * Your MinStack object will be instantiated and called as such:
 * var obj = new MinStack()
 * obj.push(x)
 * obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.getMin()
 */
// @lc code=end

